#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <sstream>
using namespace std;

class Dictionary{
public:
    void read(string filename){
        // 创建文件输入流对象
        ifstream ifs(filename);
        // 用这个字符串接收读取的每一行的字符
        string line;
        while(getline(ifs,line)){
            // getline()用来接收一行的数据内容
            // 每一行数据使用空格来分割存入写入word
            istringstream iss(line);
            string word;
            while(iss >> word){
                _dict[word]++;
            }
        }
        ifs.close();
    }

    void write(string filename){
        ofstream ofs(filename);
        auto it = _dict.begin();
        while(it != _dict.end()){
            ofs << it->first << " " << it->second << endl;
            ++it;
        }
        ofs.close();
    }

private:
    map<string, int> _dict;
};

void test(){
    Dictionary dict;
    dict.read("The_Holy_Bible.txt");
    dict.write("bible.txt");
}

int main(int atgc, char * argv[])
{
    test();
    return 0;
}

